package com.hbvtc.xxxy.nikeSale.daos;
/*
 * 会员的数据信息
 */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.hbvtc.xxxy.nikeSale.models.Vips;
import com.hbvtc.xxxy.nikeSale.utils.DbManager;

public class Vipdao {
	Connection conn;
	String sql;
	PreparedStatement pre;
	ResultSet rSet;
	
	public Vips select(String vip2){
		Vips vip=new Vips();
	conn=DbManager.getconn();
	sql="select * from vip where telephone=?";			
	try {
		pre=conn.prepareStatement(sql);
		pre.setString(1, vip2);
		rSet=pre.executeQuery();
		while (rSet.next()) {
			vip.setTelephone(rSet.getString("telephone"));
			vip.setName(rSet.getString("name"));
			vip.setPwd(rSet.getString("pwd"));
			vip.setBalance(rSet.getDouble("balance"));
			vip.setIntegration(rSet.getDouble("integration"));
		}	
	} catch (SQLException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	return vip;
}
	public boolean sss(String id) throws SQLException{
		sql="select telephone from vip where telephone=?";
		conn=DbManager.getconn();
		pre=conn.prepareStatement(sql);
		pre.setString(1,id);
		rSet=pre.executeQuery();
		String i=null;
		while (rSet.next()) {
				i=rSet.getString("telephone");
		}
		if(i==null){
			return false;
		}else {
			return true;
		}
	}

	public void addshanpin(Vips goods) throws SQLException {
		conn = DbManager.getconn();
		sql = "insert into vip (telephone,name,pwd,balance)values(?,?,?,?)";	    
		pre = conn.prepareStatement(sql);
		pre.setString(1, goods.getTelephone());
		pre.setString(2, goods.getName());
		pre.setString(3, goods.getPwd());
		pre.setDouble(4, goods.getBalance());
		pre.execute();// 执行SQL语句ps 		
	}
	
	public boolean ss(String id,String pwd) throws SQLException{
		sql="select telephone from vip where telephone=? and pwd=?";
		conn=DbManager.getconn();
		pre=conn.prepareStatement(sql);
		pre.setString(1,id);
		pre.setString(2,pwd);
		rSet=pre.executeQuery();
		String i=null;
		while (rSet.next()) {
				i=rSet.getString("telephone");
		}
		if(i==null){
			return false;
		}else {
			return true;
		}
	}

	public void update(String pwd ,String id) throws SQLException{
		conn=DbManager.getconn();
		sql="update vip set pwd=? where telephone=?;";
		pre=conn.prepareStatement(sql);
		pre.setString(1, pwd);
		pre.setString(2, id);
		pre.execute();
	}
	public void updateprice(String price, String id) throws SQLException{
		conn=DbManager.getconn();
		sql="update vip set balance=balance+? where telephone=?";
		pre=conn.prepareStatement(sql);
		pre.setDouble(1,Integer.parseInt(price));
		pre.setString(2, id);
		pre.execute();
	}

	public boolean selectvip(String id,String pwd) throws SQLException{
		conn=DbManager.getconn();
		sql="select * from vip where telephone=? and pwd=?";
		pre=conn.prepareStatement(sql);
		pre.setString(1, id);
		pre.setString(2, pwd);
		rSet=pre.executeQuery();
		String i=null;
		while (rSet.next()) {
				i=rSet.getString("name");
		}
		if(i==null){
			return false;
		}else {
			return true;
		}
	}
}